package com.qf.gateway.application.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 局部过滤器
 */
@Component
public class MyGatewayFilter extends AbstractGatewayFilterFactory implements GatewayFilter {

//    @Override
//    public GatewayFilter apply(Object config) {
//        return (exchange, chain) -> {
//            System.out.println("局部过滤器触发");
//            return chain.filter(exchange);
//        };
//    }


    @Override
    public GatewayFilter apply(Object config) {
        return this;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("局部过滤器触发");
        return chain.filter(exchange);
    }

    @Override
    public String name() {
        return "hello";
    }


}

